﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Common;
using DataAccess;

namespace BusinessLogic
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "WCFProducts" in code, svc and config file together.
    public class WCFProducts : IWCFProducts
    {
        /// <summary>
        /// Gets a product according to it's ID
        /// </summary>
        /// <param name="productID"></param>
        /// <returns>A product object containg the details according to the product's id</returns>
        public Product GetProduct(int productID)
        {
            return new ProductsRepository().GetProduct(productID);
        }

        /// <summary>
        /// Gets all products
        /// </summary>
        /// <returns>A list of products</returns>
        public IEnumerable<Product> GetProducts()
        {
            return new ProductsRepository().GetProducts();
        }

        /// <summary>
        /// Gets a product's comments
        /// </summary>
        /// <param name="productID"></param>
        /// <returns>A list of comments for the product with that ID</returns>
        public IEnumerable<Comment> GetCommentsForProduct(int productID)
        {
            return new CommentsRepository().GetCommentsForProduct(productID);
        }

        /// <summary>
        /// Gets a product's rating value
        /// </summary>
        /// <param name="productID"></param>
        /// <returns>The product's rating for the product with that ID</returns>
        public decimal GetRatingForProduct(int productID)
        {
            return new RatingsRepository().GetRatingForProduct(productID);
        }

        /// <summary>
        /// Gets the number of ratings for the product with the id passed
        /// </summary>
        /// <param name="productID"></param>
        /// <returns>An integer value of the number of ratings placed for this product</returns>
        public int GetNoOfProductRates(int productID)
        {
            return new RatingsRepository().GetNoOfProductRates(productID);
        }

        /// <summary>
        /// Gets the number of comments for the product with the id passed
        /// </summary>
        /// <param name="productID"></param>
        /// <returns>An integer value of the number of comments posted for this product</returns>
        public int GetNoOfProductComments(int productID)
        {
            return new CommentsRepository().GetNoOfProductComments(productID);
        }

        /// <summary>
        /// Gets the average rating for the product with the id passed
        /// </summary>
        /// <param name="productID"></param>
        /// <returns>A decimal value of the average rating by dividing</returns>
        public decimal CalculateProductAvgRating(int productID)
        {
            return new RatingsRepository().CalculateProductAvgRating(productID);
        }

        /// <summary>
        /// Gets a list of all categories
        /// </summary>
        /// <returns>A list of the categories</returns>
        public IEnumerable<Category> GetCategories()
        {
            return new CategoriesRepository().GetCategories();
        }

        /// <summary>
        /// Gets a list of products by the product's name
        /// </summary>
        /// <param name="name"></param>
        /// <returns>A product or products containg part of the name passed</returns>
        public IEnumerable<Product> GetProductsByName(string name)
        {
            return new ProductsRepository().GetProductsByName(name);
        }

        /// <summary>
        /// Gets a list of products found in the category chosen
        /// </summary>
        /// <param name="CategoryID"></param>
        /// <returns>A product or products found under that category</returns>
        public IEnumerable<Product> GetProductByCategory(int CategoryID)
        {
            return new ProductsRepository().GetProductByCategory(CategoryID);
        }

        /// <summary>
        /// Gets a list of products and orders by the date
        /// </summary>
        /// <returns>All products in a list</returns>
        public IEnumerable<Product> GetProductsByDateListed()
        {
            return new ProductsRepository().GetProductsByDateListed();
        }

        /// <summary>
        /// Gets a list of products and orders by the price in ascending order
        /// </summary>
        /// <returns>All products in a list</returns>
        public IEnumerable<Product> GetProductsByPriceAsc()
        {
            return new ProductsRepository().GetProductsByPriceAsc();
        }

        /// <summary>
        /// Gets a list of products and orders by the price in descending order
        /// </summary>
        /// <returns>All products in a list</returns>
        public IEnumerable<Product> GetProductsByPriceDesc()
        {
            return new ProductsRepository().GetProductsByPriceDesc();
        }

        /// <summary>
        /// This Method get's the product's details from a fault according to the username
        /// </summary>
        /// <param name="username"></param>
        /// <returns>A product object containg the details</returns>
        public IEnumerable<Product> GetProductNameInUserFaults(string username)
        {
            return new ProductsRepository().GetProductNameInUserFaults(username);
        }

        /// <summary>
        /// This method gets the details of the previous product and updates the product's details by subtracting the quantity of the product 
        /// </summary>
        /// <param name="productToUpdate"></param>
        public void UpdateProduct(Product productToUpdate)
        {
            new ProductsRepository().UpdateProduct(productToUpdate);
        }

        /// <summary>
        /// Gets a list of all faults
        /// </summary>
        /// <returns>A list of faults</returns>
        public IEnumerable<Fault> GetFaultStatus()
        {
            return new FaultsRepository().GetFaultStatus();
        }
    }
}
